//const baseUrl = "http://192.168.1.74:8080/mps";
//const baseUrl = "http://192.168.1.90:8080/mps";
//const baseUrl = "http://192.168.1.26:8081/mps";
// const baseUrl = "http://192.168.1.116:39527/mps";
//const baseUrl = "https://3w554c6204.picp.vip/mps";
const baseUrl = "https://364575kx74.eicp.vip/mps";
	const requestUrl = {
	  imageUrl: baseUrl + "/push/file?path=",
	  bannerImageUrl: baseUrl,
	  autoLogin_post: baseUrl + '/rs/login/tokenLogin', // 自动登录
	  login_post: baseUrl + '/rs/login/userLogin', // 登录
	  banner_get: baseUrl + '/rs/advertisement/list', // 首页banner图列表
	  newActivity_get: baseUrl + "/rs/activity/notice", // 获取最新活动
	  productList_get: baseUrl + '/rs/product/product/list', // 获取产品包
	  productById_get: baseUrl + '/rs/product/info', // 根据id获取产品包详细信息
	  updateUserInfo_post: baseUrl + '/rs/user/updateUserInfo', //更新用户信息
	  businessInfo_get: baseUrl + '/rs/user/businessInfo', // 获取消费记录
	  stbInfo_get: baseUrl + '/rs/user/stbInfo', // 获取集团用户的终端列表，用于授权
	  authRefresh_get: baseUrl + '/rs/user/authorizeRefresh', // 重新获取授权
	  hotline_get: baseUrl + '/rs/dispatch/hotline', // 获取客服电话
	  getQuestionReply_get: baseUrl + '/rs/user/getQuestionReply', //获取常见问题列表
	  repair_post: baseUrl + '/rs/dispatch/uploadComplaint', //提交报修 //表单提交
	  changePwd_post: baseUrl + '/rs/user/changePwd', //修改登录密码
	  changePayPwd_post: baseUrl + '/rs/user/changePayPwd', //修改支付密码
	  productBuyInfo_get: baseUrl + '/rs/user/productInfoChao', //获取购买信息
	  createOrder_post: baseUrl + '/rs/wallet/balance/order', //创建订单
	  createGroupOrder_post: baseUrl + '/rs/wallet/balance/orderGroup', //创建订单（集团用户）
	  placeAnOrder_post: baseUrl + '/rs/wallet/appPay/pay', // 下单
	  checkPayPwd_post: baseUrl + '/rs/wallet/checkPayPwd', // 余额支付
	  getCardListByType_get: baseUrl + '/rs/user/getCardListByType', // 获取未授权、已授权终端列表（集团用户）
	  loginBuyforOther: baseUrl + '/rs/login/getLoginInfo',//代买登录，获取代买用户信息
		login_card: baseUrl + '/rs/login/login', // 卡号登录
		verify_registered: baseUrl + '/rs/registered/verify', // 核实卡注册状态
		
		
		bindUserCard: baseUrl + '/rs/registered/saveUserCard',//绑定副卡
		getHistoryOrder: baseUrl + '/rs/invoice/history',//获取历史订单信息	 
		getOrderbyID: baseUrl + '/rs/invoice/print',//获取订单信息	
		getOrderbyCode: baseUrl + '/rs/product/productList',//获取产品列表信息，通过微信code	
	};
	const requestMethod = {
	  POST: 'POST',
	  GET: 'GET'
	};
export default {	
	Request(options)
	{
		return new Promise((resolve, reject) => {
			console.log('request:');
			console.log(options.datas);
			uni.request({
				url: options.url,
				method:options.method || "get",
				data:options.datas || {},
				header:{'content-type':'application/json;charset=UTF-8',},
				success:res=>{
					console.log('response:')
					if(res.statusCode === 200)
					{	
						if (res.data.status === '40101'){
							//store.logout();	
							
							uni.showToast({
							    title: '登录信息已过期，请重新登录！',
							    icon: "none"
							});
							uni.reLaunch({
								url:"/pages/login/login"
							})
						}						
					}
					else{
						uni.showToast({
						    title: '请求错误，code=' + res.statusCode,
						    icon: "none"
						})						
					}
					resolve(res);
				},
				fail:err=>{
					reject(err);
				},
				complete:()=>{
					
				}
			})
		})
	},
	
	UploadFile(Options)
	{
		console.log('UploadFile....');
		console.log(Options.url)
		return new Promise((resolve, reject) =>{
			uni.uploadFile({
				url:Options.url,
				filePath: Options.filePath === '' ? '/static/images/bill.png' : Options.filePath,
				name: Options.name,
				formData: Options.formDatas,
				header: {
					'content-type': 'multipart/form-data'
				},
				success: (res) => {
					console.log('response:');					
					resolve(res);
				},
				fail:(err) => {
					reject(err);
				},
				complete:()=>{
				},
			})
		})			
	},
	DownloadFile(Options)
	{
		var urls = Options.url.split("=");		
		var downloadUrl = urls[1].replace(/\\/g, "%5C");
		downloadUrl = urls[0] + '=' + downloadUrl;
		console.log('down picture url....')
		console.log(downloadUrl);		
		
		return new Promise((resolve, reject) =>{
			uni.downloadFile({
				url:downloadUrl,
				success: (res) => {
					console.log('response:');
					console.log(res);
					if (res.statusCode == 200) {
						var position = Options.url.lastIndexOf('=') + 1;
						var urlndex = Options.url.substring(position);
						console.log(urlndex);
						var tempImagePath = uni.getStorageSync('tempImagePath');
						if (!tempImagePath){
							tempImagePath = {};
						}
						tempImagePath[urlndex] = res.tempFilePath;
						uni.setStorageSync('tempImagePath', tempImagePath);
						console.log(tempImagePath);
					}
					resolve(res);
				},
				fail:(err) => {
					reject(err);
				},
				complete:()=>{					
				},
			})
		})
	},
	formatTime(time){
		return time.substring(0, time.length - 2);	    
	},
	requestUrl,
	requestMethod
}

